<style>
.pure_form_extra { background: #fff; padding: 10px; border: 1px solid #aaa; border-radius: 8px; }
.pure_form_extra span { font-size: 12px !important; color: #666; font-family: Trebuchet MS; }
.pure_form_extra a { font-size: 13px !important; color: #666; font-family: Trebuchet MS; }
table.list { border-left: 1px solid #aaa; border-top: 1px solid #aaa; font-size: 13px; width: 690px; }
table.list th,table.list td { vertical-align: middle; text-align: left;padding: 0 5px; border-right: 1px solid #aaa; border-bottom: 1px solid #aaa; }
table.list th { height: 28px; background-color: #ddd; font-weight: bold; color: #333; }
table.list td { height: 25px; word-wrap: break-word; overflow: hidden; }
table.list tr.rowodd td { background-color: #eee; }
table.list tr.roweven td { background-color: #fff; }
table.list tr.rowodd:hover td { background-color: #f4f3b2; }
table.list tr.roweven:hover td { background-color: #f4f3b2; }
table.list .date { float: right; color: #666; font-size: 11px !important; }
</style>

<?php
$pg = Utils::get_param('pg', 1);
$cat = Utils::get_param('cat', NULL);

$opts = new stdClass();
$opts->cd = 't.tag_id LIKE :v1';
$opts->cdv = array(':v1' => '%,' . $cat . ',%');
$data = $orm->get('pb_ecom_article', 't.date', 'DESC', $pg, SIZE, $opts);
?>

<table cellpadding=0 cellspacing=0>
  <tr>
    <td style="width: 730px; vertical-align: top; padding-right: 10px;">
      <div class="pure-form pure_form_extra" style="margin-bottom: 10px;">
        <a>您的位置</a>
        <i class="fa fa-arrow-right></i>
        <a href="#" onclick="return false;"><?php echo $cat; ?></a>
      </div>
      <div class="pure-form pure_form_extra">
        <table class="list" cellpadding=0 cellspacing=0>
          <tbody id="art_body"></tbody>
        </table>
        <div>&nbsp;</div>
        <div id="pagination"></div>
      </div>
    </td>
    <td style="width: 230px; vertical-align: top;"><?php include PLGN_DIR . basename(dirname(__FILE__)) . '/inc.rightbar.php'; ?></td>
  </tr>
</table>
<div>&nbsp;</div>

<script type="text/javascript">
  var __cat = '<?php echo $cat; ?>';
  var __data = JSON.parse('<?php echo addslashes(json_encode($data)); ?>');
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  var __id = '<?php echo $app_data->param_id; ?>';
  
  $(function(){
    $('#pagination').pagination({
      items: __data.t,
      itemsOnPage: __data.s,
      currentPage: __data.p,
      cssStyle: 'compact-theme',
      onPageClick: function(pageNumber, event) {
        return Url.redirect(__redmd, __sys + '.php?i=' + __id + '&pg=' + pageNumber + '&cat=' + __cat);
      }
    });
    render();
  });


  function render() {
    $('#art_body').empty();
    for (var idx in __data.d) {
      var itm = __data.d[idx];
      $('#art_body').append(
        '<tr class="' + ((idx % 2 ==0) ? 'roweven' : 'rowodd') + '">' +
          '<td>' +
            '<span class="date">' + itm.date.split(' ')[0] + '</span>' +
            '<a href="#" onclick="return Url.redirect(__redmd, \'' + __sys + '.php?i=' + __id + '&__file=index_article&id=' + itm.id + '&cat=' + __cat + '\');">' + itm.title + '</a>' +
          '</td>' +
        '</tr>'
      );
    }

    if (__data.length == 0) {
      $('#art_body').append('<tr class="roweven"><td colSpan="7">&nbsp;</td></tr>')
    } 
  };
</script>